home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 342_01.zip / DIOFNC11.TXT < prev    next >
Text File  |  1993-04-03  |  6KB  |  137 lines

  1. *   ----------------------------------------------------------------------
  2. *   File        :   DIOFNC11.TXT
  3. *   Creator     :   Blake Miller
  4. *   Version     :   01.01.00    February 1991
  5. *   Purpose     :   Describe DIOFNC11.C Functions
  6. *   Revision    :   February 28, 1991
  7. *   -----------------------------------------------------------------------
  8.  
  9. WARNING:
  10. --------
  11.  
  12.     I do not have a multi-port board on which to test these functions.
  13. The single-port functions work correctly, and I wrote these multi-port
  14. functions as an extension to those single-port functions for those of you
  15. with multi-port boards.  These functions here 'seem' correct, but are
  16. not truly debugged.  You might say they are written on 'good faith'.
  17. (In other words, they compiled, so they must work, right?   Ha Ha Ha...
  18. I love that line!)
  19.  
  20. OVERVIEW:
  21. ---------
  22.  
  23.     Many Digital I/O boards have more than one Intel 8255 on them.  The
  24. other functions in the library are used for working with one digital I/O
  25. port at a time.  If several digital ports are in use in your system, then
  26. it may be more convenient to use the Port Array (_pa_) functions.  These
  27. functions support a virtually unlimited number of digital I/O ports (limited
  28. by the system's amount of free memory or available 80X86 hardware addresses,
  29. whichever you run out of first...).
  30.     I generall only need to toggle individual bits at a time.  The functions
  31. supplied support the digital output port array in this manner.  If necessary,
  32. you can obtain the address of any individual element in the array and
  33. then implement the individual port manipulation functions (which generally
  34. require the address of the DIODAT data as one of the arguments).
  35.  
  36.  
  37. IMPLEMENTATION:
  38. ---------------
  39.  
  40.     Since I advocate using defines for bits and using bit associated
  41. digital I/O instead of obscure references such as:
  42.  
  43.     data = inp( 0x300 );            /* read in data     */
  44.     outp ( 0x300, data | 0x0010 );  /* toggle bit 4 on  */
  45.  
  46.     Huh????????
  47.  
  48.     Instead, you can create legible (maintainable!) code:
  49.  
  50.     #define     MOTOR_BIT   32
  51.     #define     MOTOR_ON     1
  52.     #define     MOTOR_OFF    0
  53.  
  54.     dio_pa_bitput (MOTOR_BIT, MOTOR_ON);    /* turn motor on!   */
  55.  
  56.     Seems a little easier to read, and not a whole lot less efficient.
  57. As I had said, many boards have more than one 8255 (Notice the motor was
  58. located at bit 32...).  In order to accomodate this system for multiple
  59. ports, there is memory for an array of DIODAT data allocated by the
  60. dio_pa_aloc(count) function.  You pass how many 8255s are in the system
  61. (or on multiple boards for that matter, the functions do not know the
  62. difference....), and the 8255 base addresses do not have to be located at
  63. consecutive 80X86 hardware port addresses.  This sets up the data array.
  64.  
  65.     The next important step is to remember to call dio_pa_free() before
  66. exiting the program so that the memory is returned to the operating system.
  67. I have conveniently made dio_pa_aloc() a void function returning a void type
  68. so that it can be installed to be called at exit with the atexit() function.
  69. It does no harm to call dio_pa_aloc() before memory has been allocated with
  70. dio_pa_aloc(void) function.  Those two functions, then, reserve and free the
  71. memory for the DIODAT data buffers.
  72.  
  73.     Next, the address of each 8255 must be set.  Use the function
  74. dio_pa_setadr (element, address) and call it once for each 8255 in
  75. the system.  The base address of each 8255 must be used.  On most boards,
  76. each 8255 on the board is 4 addresses away from the previous one.  So, for
  77. example, if your board has four 8255s (Computer Boards, Inc. CIO-DIO96
  78. is one such board) and the board's base address is set to 0x300, then the
  79. first 8255 address (Element 0) is set up with this call:
  80.  
  81.     #define     DIO96_BASE  0x300
  82.  
  83.     dio_pa_setadr (0, DIO86_BASE);
  84.  
  85.     Since there are four 8255 on the board, you can even set up a loop:
  86.  
  87.     for (i = 0; i < 4; i++ ){
  88.         dio_pa_setadr (i, DIO96_BASE + (i * 4) );
  89.         }
  90.  
  91.     So far, we have memory and the base addresses set up.  Next step is to
  92. program the I/O direction of the ports on the individual 8255.  The default
  93. direction is input (According to Intel documentation - RESET.  A "high" on
  94. this input clears the control register and all ports (A, B, C) are set to
  95. the input mode.").  It is a good idea to set up all your ports and then
  96. do the approriate bit reads or writes to get the data set up correctly.
  97. That is, to get all the data and ports into a 'known' state.
  98.     To set up all the ports as output, you can use a loop like this:
  99.  
  100.     for (i = 0; i < num_port; i++ ){
  101.         dio_pa_config (i, 0, 0, 0, 0);
  102.         }
  103.  
  104.     With the 8255 addresses set, and the port I/O directiosn established,
  105. you can now proceed to use the bit functions to individually set or clear
  106. bits in the system.  Note that the total number of bits available (Base 1)
  107. is num_bits = 24 * num_port.   A loop to read all bits and print out the
  108. state of each one as SET or CLEAR, can be written like this:
  109.  
  110.     short   num_bits  = 24 * num_port;
  111.     short   bit_state = 0;
  112.  
  113.     for (bit = 0; bit < num_bits; bit++ ){
  114.         dio_pa_bitget (bit, &bit_state);
  115.         if ( bit_state )    printf ("SET  \n");
  116.         else                printf ("CLEAR\n");
  117.         }
  118.  
  119.     A loop to sett all bits can be written like this:
  120.  
  121.     for (bit = 0; bit < num_bits; bit++ ){
  122.         dio_pa_bitput (bit, 1);
  123.         }
  124.  
  125. SUMMARY:
  126. --------
  127.  
  128.     For a more detailed explanation of what each function does,
  129. look at the source code!  I have written an UNTESTED program called
  130. DIOTST02.C which gives a general idea of how I thought the functions
  131. coudl be used.  It does not do anything useful, but demonstrates the
  132. order in which things should be set up.
  133.  
  134. *   ----------------------------------------------------------------------
  135. *   END DIOFNC11.TXT Text Description File
  136. *   ----------------------------------------------------------------------
  137.